
//
//  PurchaseHomeViewController.m
//  YYPHSpeedJump
//
//  Created by sujiang on 15/12/16.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "PurchaseHomeViewController.h"
#import "PurchaseCollectionViewCell.h"
#import "MyPurchaseViewController.h"
#import "PurchaseDetailViewController.h"
#import "PurchaseHistoryViewController.h"
#import "NewPurchaseViewController.h"
#import "JoinPurchaseViewController.h"
#import "AddPuechaseViewController.h"
@interface PurchaseHomeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UITableViewDataSource,UITableViewDelegate>
{
    NSInteger page;
    NSInteger status;
}
@end

@implementation PurchaseHomeViewController
- (NSMutableArray *)topThreeArr
{
    if (!_topThreeArr) {
        _topThreeArr = [NSMutableArray array];
    }
    return _topThreeArr;
}
- (NSMutableArray *)myxyArray
{
    if (!_myxyArray) {
        _myxyArray = [NSMutableArray array];
    }
    return _myxyArray;
}

- (NSMutableArray *)xyArray
{
    if (!_xyArray) {
        _xyArray = [NSMutableArray array];
    }
    return _xyArray;
}
- (NSMutableArray *)joinArray
{
    if (!_joinArray) {
        _joinArray = [NSMutableArray array];
        
    }
    return _joinArray;
}


- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
    }

- (void)viewDidAppear:(BOOL)animated
{
    page =1;
    status = 0;
    [self requestData];
    [self.tabelView reloadData];


}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kColors(239, 239, 241, 1);
    self.navigationItem.title = @"心愿墙";
    [self addSubViews];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60, 44)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    UIButton *btn2= [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setBackgroundImage:[UIImage imageNamed:@"yiwancheng"] forState:UIControlStateNormal];
    btn2.titleLabel.font = [UIFont systemFontOfSize:15];
    [btn2 addTarget:self action:@selector(purchaseHistoryAction:) forControlEvents:UIControlEventTouchUpInside];
    btn2.frame = CGRectMake(0, 11, 60, 22);
    [view addSubview:btn2];
}

- (void)requestData
{
   

    //最新心愿
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrl,kXYHomeUrl];
    NSDictionary *dict = @{@"page":[NSNumber numberWithInteger:page]};
    [NetworkHandle getUpDataWithUrl:urlStr class:NSClassFromString(@"PurchaseModel") dictionary:dict firstKey:@"data" secondKey:@"list" success:^(NSArray *array) {
       // [self.xyArray removeAllObjects];
         [self.xyArray removeAllObjects];
        [self.xyArray addObjectsFromArray:array];
        [self.tabelView.header endRefreshing];
        [self.collectionView reloadData];
        
    }];
    //我发起的心愿
    
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"logined"]) {
        self.loginBtn.hidden = NO;
        
    }else{
        self.loginBtn.hidden = YES;

    NSString *myXYUrlStr = [NSString stringWithFormat:@"%@%@",kBaseUrl,kMYXYUrl];
    NSDictionary *dic = @{@"u":[[NSUserDefaults standardUserDefaults] objectForKey:@"user_id"], @"page":[NSNumber numberWithInteger:page],@"status":[NSNumber numberWithInteger:status]};
    [NetworkHandle getUpDataWithUrl:myXYUrlStr class:NSClassFromString(@"PurchaseModel") dictionary:dic firstKey:@"data" secondKey:@"list" success:^(NSArray *array) {
        [self.myxyArray removeAllObjects];
        [self.myxyArray addObjectsFromArray:array];
        [self.MyXyCollectionView reloadData];
    }];
    NSString *joinUrlStr = [NSString stringWithFormat:@"%@%@",kBaseUrl,kJoinXYUrl];
    NSDictionary *joinDic =@{@"u":[[NSUserDefaults standardUserDefaults]objectForKey:@"user_id"],@"pageIndex":[NSNumber numberWithInteger:page],@"pageSize":[NSNumber numberWithInteger:12]};
    [NetworkHandle getDataWithUrl:joinUrlStr class:NSClassFromString(@"PurchaseModel") dictionary:joinDic firstKey:@"data" success:^(NSArray *array) {
        [self.joinArray removeAllObjects];
        [self.joinArray addObjectsFromArray:array];
        [self.InvolvementCV reloadData];
    }];
    

    }
  
    //心愿Top3
    [NetworkHandle getUpDataWithUrl:urlStr class:NSClassFromString(@"PurchaseModel") dictionary:dict firstKey:@"data" secondKey:@"first_three" success:^(NSArray *array) {
        [self.topThreeArr removeAllObjects];
        [self.topThreeArr addObjectsFromArray:array];
        PurchaseModel *model1 = self.topThreeArr[0];
        PurchaseModel *model2 = self.topThreeArr[1];
        PurchaseModel *model3 = self.topThreeArr[2];
        self.goodNameLabel1.text = model1.wish_commodity_name;
        self.goodNameLabel2.text = model2.wish_commodity_name;
        self.goodNameLabel3.text = model3.wish_commodity_name;
        self.zanLable1.text = [NSString stringWithFormat:@"%@/100",model1.up_num];
        self.zanLable2.text = [NSString stringWithFormat:@"%@/100",model2.up_num];
        self.zanLable3.text = [NSString stringWithFormat:@"%@/100",model3.up_num];
        NSArray *arr= [model1.img_url componentsSeparatedByString:@";"];
        [self.imageV1 sd_setImageWithURL:[NSURL URLWithString:arr[0]] placeholderImage:nil];
         NSArray *arr1= [model2.img_url componentsSeparatedByString:@";"];
        [self.imageV2 sd_setImageWithURL:[NSURL URLWithString:arr1[0]] placeholderImage:nil];
         NSArray *arr2= [model3.img_url componentsSeparatedByString:@";"];
        [self.imageV3 sd_setImageWithURL:[NSURL URLWithString:arr2[0]] placeholderImage:nil];
        NSArray *timeArr1 = [model1.create_time componentsSeparatedByString:@" "];
        self.timeLable1.text = [NSString stringWithFormat:@"%@",timeArr1[0]];
        NSArray *timeArr2 = [model2.create_time componentsSeparatedByString:@" "];
        self.timeLable2.text = [NSString stringWithFormat:@"%@",timeArr2[0]];
        NSArray *timeArr3 = [model3.create_time componentsSeparatedByString:@" "];
        self.timeLable3.text = [NSString stringWithFormat:@"%@",timeArr3[0]];
        [self.tabelView reloadData];
          }];

    
}
- (void)addSubViews
{
     self.tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-64)];
     self.tabelView.delegate = self;
     self.tabelView.dataSource  = self;
     self.tabelView.backgroundColor = [UIColor  colorWithPatternImage:[UIImage imageNamed:@"心愿背景视图"]];
    self.tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview: self.tabelView];
    self.tabelView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRereshing)];
    self.baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 258)];
    self.tabelView.tableHeaderView = self.baseView;
    [self addBaseView];
}
#pragma mark-------------下拉刷新 上拉加载------------------
- (void)headerRereshing
{
    page =1;
    [self requestData];
    
}



#pragma mark -------tableViewDelegate--------------
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    if (indexPath.row ==0) {
      
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
        label.text =@"最新心愿";
        label.textColor =[UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.backgroundColor = kColors(218, 166, 46, 1);
        label.font = [UIFont systemFontOfSize:15];
        [cell addSubview:label];

        UIView *baseView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 30, kScreenWidth, 160)];
        [cell addSubview:baseView1];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing =9*kWidthScale;
        layout.itemSize = CGSizeMake((kScreenWidth-45*kWidthScale)/3, 134);
        layout.sectionInset = UIEdgeInsetsMake(9, 9*kWidthScale, 9, 9*kWidthScale);
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        self.collectionView = [[UICollectionView alloc] initWithFrame:baseView1.bounds collectionViewLayout:layout];
        self.collectionView.delegate = self;
        self.collectionView.dataSource =self;
        self.collectionView.showsHorizontalScrollIndicator =NO;
        self.collectionView.backgroundColor = [UIColor clearColor];
        self.collectionView.pagingEnabled = YES;
        self.collectionView.userInteractionEnabled = YES;
         [baseView1 addSubview:self.collectionView];
        self.xyMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.xyMoreBtn.backgroundColor = [UIColor clearColor];
        [self.xyMoreBtn setBackgroundImage:[UIImage imageNamed:@"查看更多"] forState:UIControlStateNormal];
        [self.xyMoreBtn addTarget:self action:@selector(xyMoreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.collectionView addSubview:self.xyMoreBtn];

        //注册单元格
        [self.collectionView registerNib:[UINib nibWithNibName:@"PurchaseCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"purchaseCell"];

    }
    if (indexPath.row ==1) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
        label.text =@"我发起的心愿";
         label.textColor =[UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.backgroundColor = kColors(218, 166, 46, 1);
        label.font = [UIFont systemFontOfSize:15];
        [cell addSubview:label];
        UIView *addView = [[UIView alloc]initWithFrame:CGRectMake(9, 43, (kScreenWidth-45*kWidthScale)/3, 134)];
        UIImageView *bgImageV =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,  (kScreenWidth-45*kWidthScale)/3, 134)];
        bgImageV.image = [UIImage imageNamed:@"心愿墙列表背景"];
        [addView addSubview:bgImageV];
        UIView *bgview =[[UIView alloc]initWithFrame:CGRectMake(3, 12, addView.frame.size.width-6,105)];
        bgview.backgroundColor =  [UIColor blackColor];
        bgview.alpha = 0.26;
        [addView addSubview:bgview];
        UIImageView *addImage = [[UIImageView alloc]initWithFrame:CGRectMake((bgview.frame.size.width-50)/2, (bgview.frame.size.height-50)/2, 50, 50)];
        addImage.image = [UIImage imageNamed:@"XYtianjia"];
        [bgview addSubview:addImage];
        [cell addSubview:addView];
        UITapGestureRecognizer *addViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addBtnAction:)];
        addViewTap.numberOfTouchesRequired = 1;
        [addView addGestureRecognizer:addViewTap];
        UIView *baseView1 = [[UIView alloc]initWithFrame:CGRectMake((kScreenWidth-45*kWidthScale)/3+9, 30, kScreenWidth-((kScreenWidth-45*kWidthScale)/3+9), 160)];
        [cell addSubview:baseView1];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing =9*kWidthScale;
        layout.itemSize = CGSizeMake((kScreenWidth-45*kWidthScale)/3, 134);
        layout.sectionInset = UIEdgeInsetsMake(9, 9*kWidthScale, 9, 9*kWidthScale);
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        self.MyXyCollectionView = [[UICollectionView alloc] initWithFrame:baseView1.bounds collectionViewLayout:layout];
        self.MyXyCollectionView.delegate = self;
        self.MyXyCollectionView.dataSource =self;
        self.MyXyCollectionView.showsHorizontalScrollIndicator =NO;
        self.MyXyCollectionView.backgroundColor = [UIColor clearColor];
        self.MyXyCollectionView.pagingEnabled = YES;
        self.MyXyCollectionView.userInteractionEnabled = YES;
        [baseView1 addSubview:self.MyXyCollectionView];
        self.myxyMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.myxyMoreBtn.backgroundColor = [UIColor clearColor];
        [self.myxyMoreBtn setBackgroundImage:[UIImage imageNamed:@"查看更多"] forState:UIControlStateNormal];
        [self.myxyMoreBtn addTarget:self action:@selector(myxyMoreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.MyXyCollectionView addSubview:self.myxyMoreBtn];
        //注册单元格
        [self.MyXyCollectionView registerNib:[UINib nibWithNibName:@"PurchaseCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"purchaseCell"];
        self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.loginBtn.frame = CGRectMake((kScreenWidth-80)/2,50 , 80, 40);
        [self.loginBtn setTitle:@"前往登录" forState:UIControlStateNormal];
        self.loginBtn.hidden = YES;
        [cell addSubview:self.loginBtn];
    }
    if (indexPath.row ==2)
    {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
        label.text =@"我参与的心愿";
        label.textColor =[UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.backgroundColor = kColors(218, 166, 46, 1);
        label.font = [UIFont systemFontOfSize:15];
        [cell addSubview:label];
       
        
    
        UIView *baseView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 30, kScreenWidth, 160)];
        [cell addSubview:baseView1];
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumInteritemSpacing = 0;
        layout.minimumLineSpacing =9*kWidthScale;
        layout.itemSize = CGSizeMake((kScreenWidth-45*kWidthScale)/3, 134);
        layout.sectionInset = UIEdgeInsetsMake(9, 9*kWidthScale, 9, 9*kWidthScale);
        [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        self.InvolvementCV = [[UICollectionView alloc] initWithFrame:baseView1.bounds collectionViewLayout:layout];
        self.InvolvementCV.delegate = self;
        self.InvolvementCV.dataSource =self;
        self.InvolvementCV.showsHorizontalScrollIndicator =NO;
        self.InvolvementCV.backgroundColor = [UIColor clearColor];
        self.InvolvementCV.pagingEnabled = YES;
        self.InvolvementCV.userInteractionEnabled = YES;
        [baseView1 addSubview:self.InvolvementCV];
        self.joinxyMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.joinxyMoreBtn.backgroundColor = [UIColor clearColor];
        [self.joinxyMoreBtn setBackgroundImage:[UIImage imageNamed:@"查看更多"] forState:UIControlStateNormal];
        [self.joinxyMoreBtn addTarget:self action:@selector(joinxyMoreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.InvolvementCV addSubview:self.joinxyMoreBtn];
        //注册单元格
        [self.InvolvementCV registerNib:[UINib nibWithNibName:@"PurchaseCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"purchaseCell"];
        self.loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.loginBtn.frame = CGRectMake((kScreenWidth-80)/2,50 , 80, 40);
        [self.loginBtn setTitle:@"前往登录" forState:UIControlStateNormal];
        self.loginBtn.hidden = YES;
        [cell addSubview:self.loginBtn];

    }
    return cell;

    }
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 190;
}
#pragma mark -------collectionViewDelegate--------------

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (collectionView  == self.MyXyCollectionView)
    {
        return self.myxyArray.count;
        
    }
    if (collectionView == self.collectionView) {
         return self.xyArray.count;
    }
   
    else
    {
        return self.joinArray.count;
    }
   
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PurchaseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"purchaseCell" forIndexPath:indexPath];
    if (collectionView == self.collectionView) {
        cell.backgroundColor = [UIColor whiteColor];
        cell.model = self.xyArray[indexPath.row];
    }
    if (collectionView  == self.MyXyCollectionView)
    {
        cell.backgroundColor = [UIColor whiteColor];
        cell.model = self.myxyArray[indexPath.row];
    }
    if (collectionView  == self.InvolvementCV)
    {
        cell.backgroundColor = [UIColor whiteColor];
        cell.model = self.joinArray[indexPath.row];
    }

    return cell;
}

//添加头视图
- (void)addBaseView
{
   
    UILabel *titlelable = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-113)/2, 15, 113, 34)];
    titlelable.text = @"心愿排行榜";
    titlelable.backgroundColor =kColors(218, 166, 46, 1);
    titlelable.textColor = [UIColor whiteColor];
    titlelable.textAlignment = NSTextAlignmentCenter;
    titlelable.layer.cornerRadius = 5;
    titlelable.layer.masksToBounds = 5;
    titlelable.font = [UIFont systemFontOfSize:15];
    [self.baseView addSubview:titlelable];
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(16, 87, 128, 140)];
    view2.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"心愿排行背景"]];
    view2.layer.cornerRadius = 5;
    view2.transform =CGAffineTransformMakeRotation(M_PI/36);
    [self.baseView addSubview:view2];
   self.imageV2 = [[UIImageView alloc]initWithFrame:CGRectMake(7, 7, 114, 114)];
    
    [view2 addSubview:self.imageV2];
    UIView *goodNameV2 =[[UIView alloc]initWithFrame:CGRectMake(7, 100, 114, 21)];
    goodNameV2.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nameBackgrondColor"]];
    [view2 addSubview:goodNameV2];
    self.goodNameLabel2 =[[UILabel alloc]initWithFrame:goodNameV2.bounds];
    self.goodNameLabel2.textColor = [UIColor whiteColor];
    self.goodNameLabel2.font = [UIFont systemFontOfSize:12];
    self.goodNameLabel2.textAlignment = NSTextAlignmentCenter;
   
    [goodNameV2 addSubview: self.goodNameLabel2];
    self.zanLable2 = [[UILabel alloc]initWithFrame:CGRectMake(7, 125, 38, 10)];
    self.zanLable2.textColor = [UIColor redColor];
    self.zanLable2.font = [UIFont systemFontOfSize:10];
    [view2 addSubview:self.zanLable2];
    UIImageView *topImage2 = [[UIImageView alloc]initWithFrame:CGRectMake(36, 6, 56, 61)];
    topImage2.image = [UIImage imageNamed:@"second"];
    [view2 addSubview:topImage2];
    self.timeLable2 =[[UILabel alloc]initWithFrame:CGRectMake(view2.bounds.size.width-64, 125, 62, 12)];
    self.timeLable2.font = [UIFont systemFontOfSize:10];
    [view2 addSubview:self.timeLable2];
    
    
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(kScreenWidth-153, 87, 128, 140)];
    view3.transform = CGAffineTransformMakeRotation(M_PI/36);
    view3.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"心愿排行背景"]];
    view3.layer.cornerRadius = 5;
    [self.baseView addSubview:view3];
    self.imageV3 = [[UIImageView alloc]initWithFrame:CGRectMake(7, 7, 114, 114)];
    [view3 addSubview:self.imageV3];
    UIView *goodNameV3 =[[UIView alloc]initWithFrame:CGRectMake(7, 100, 114, 21)];
    goodNameV3.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nameBackgrondColor"]];
    [view3 addSubview:goodNameV3];
    self.goodNameLabel3 =[[UILabel alloc]initWithFrame:goodNameV3.bounds];
    self.goodNameLabel3.textColor = [UIColor whiteColor];
    self.goodNameLabel3.font = [UIFont systemFontOfSize:12];
    self.goodNameLabel3.textAlignment = NSTextAlignmentCenter;
    self.goodNameLabel3.text= @"iphone6s";
    [goodNameV3 addSubview: self.goodNameLabel3];
    self.zanLable3 = [[UILabel alloc]initWithFrame:CGRectMake(7, 125, 38, 10)];
    self.zanLable3.textColor = [UIColor redColor];
    self.zanLable3.font = [UIFont systemFontOfSize:10];
    [view3 addSubview:self.zanLable3];
    UIImageView *topImage3 = [[UIImageView alloc]initWithFrame:CGRectMake(36, 6, 56, 61)];
    topImage3.image = [UIImage imageNamed:@"third"];
    [view3 addSubview:topImage3];
    self.timeLable3 =[[UILabel alloc]initWithFrame:CGRectMake(view3.bounds.size.width-64, 125, 62, 12)];
    self.timeLable3.font = [UIFont systemFontOfSize:10];
    [view3 addSubview:self.timeLable3];

    
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake((kScreenWidth-140)/2, 71, 128, 140)];
    view1.transform = CGAffineTransformMakeRotation(-M_PI/20);
    view1.layer.cornerRadius = 5;
    view1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"心愿排行背景"]];
    [self.baseView addSubview:view1];
    self.imageV1 = [[UIImageView alloc]initWithFrame:CGRectMake(7, 7, 114, 114)];
    [view1 addSubview:self.imageV1];
    UIView *goodNameV1 =[[UIView alloc]initWithFrame:CGRectMake(7, 100, 114, 21)];
    goodNameV1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nameBackgrondColor"]];
    [view1 addSubview:goodNameV1];
    self.goodNameLabel1 =[[UILabel alloc]initWithFrame:goodNameV1.bounds];
    self.goodNameLabel1.textColor = [UIColor whiteColor];
    self.goodNameLabel1.font = [UIFont systemFontOfSize:12];
    self.goodNameLabel1.textAlignment = NSTextAlignmentCenter;
    self.goodNameLabel1.text= @"iphone6s";
    [goodNameV1 addSubview: self.goodNameLabel1];
    self.zanLable1 = [[UILabel alloc]initWithFrame:CGRectMake(7, 125, 38, 10)];
    self.zanLable1.textColor = [UIColor redColor];
    self.zanLable1.font = [UIFont systemFontOfSize:10];
    [view1 addSubview:self.zanLable1];
    UIImageView *topImage1 = [[UIImageView alloc]initWithFrame:CGRectMake(36, 6, 56, 61)];
    topImage1.image = [UIImage imageNamed:@"first"];
    [view1 addSubview:topImage1];
    self.timeLable1 =[[UILabel alloc]initWithFrame:CGRectMake(view1.bounds.size.width-64, 125, 62, 12)];
    self.timeLable1.font = [UIFont systemFontOfSize:10];
    [view1 addSubview:self.timeLable1];
    //添加点击方法
    
    UITapGestureRecognizer *firstTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap1:)];
    firstTap.numberOfTouchesRequired = 1;
    UITapGestureRecognizer *secondTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap2:)];
    firstTap.numberOfTouchesRequired = 1;
    UITapGestureRecognizer *threeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap3:)];
    firstTap.numberOfTouchesRequired = 1;
    [view1 addGestureRecognizer:firstTap];
    [view2 addGestureRecognizer:secondTap];
    [view3 addGestureRecognizer:threeTap];



}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
   
    PurchaseDetailViewController *purchaseDetailVC =[[PurchaseDetailViewController alloc]init];
    
 
    
    if (collectionView == self.collectionView) {
        purchaseDetailVC.purchaseModel =self.xyArray[indexPath.row];
        if (purchaseDetailVC.purchaseModel != nil) {
            [self.navigationController pushViewController:purchaseDetailVC animated:YES];
            self.tabBarController.tabBar.hidden = YES;
        }

    }
    if (collectionView == self.MyXyCollectionView) {
        purchaseDetailVC.purchaseModel =self.myxyArray[indexPath.row];
        if (purchaseDetailVC.purchaseModel != nil) {
            [self.navigationController pushViewController:purchaseDetailVC animated:YES];
            self.tabBarController.tabBar.hidden = YES;
        }

    }
    if (collectionView == self.InvolvementCV) {
        purchaseDetailVC.purchaseModel = self.joinArray[indexPath.row];
        if (purchaseDetailVC.purchaseModel != nil) {
            [self.navigationController pushViewController:purchaseDetailVC animated:YES];
            self.tabBarController.tabBar.hidden = YES;
        }

    }
   }
//返回这个UICollectionView是否可以被选择
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
#pragma mark----------------右滑加载更多-------------
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
//    NSLog(@"%f",scrollView.contentOffset.x);
//     NSLog(@"%f",scrollView.frame.size.width);
//     NSLog(@"%f",scrollView.contentSize.width);
    
    
    
        if (scrollView.contentOffset.x + scrollView.frame.size.width > scrollView.contentSize.width) {
        
            if (self.xyArray.count ==12 ) {
            self.xyMoreBtn.frame = CGRectMake(1437*kWidthScale, 13 , 40, 134);
            self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 50);

            }            }
            if (self.myxyArray.count ==12) {
                self.myxyMoreBtn.frame = CGRectMake(1437*kWidthScale, 13 , 40, 134);
                self.MyXyCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 50);
            }
            if (self.joinArray.count ==12) {
                self.joinxyMoreBtn.frame = CGRectMake(1437*kWidthScale, 13 , 40, 134);
                self.InvolvementCV.contentInset = UIEdgeInsetsMake(0, 0, 0, 50);
    }
    
    
    
}
//心愿历史
- (void)purchaseHistoryAction:(UIButton *)btn
{
    PurchaseHistoryViewController *historyVC = [[PurchaseHistoryViewController alloc]init];
    [self.navigationController pushViewController:historyVC animated:NO];
    self.tabBarController.tabBar.hidden = YES;
}


#pragma mark ------------点击方法----------------
//添加心愿
- (void)addBtnAction:(UIButton *)btn
{
    
    AddPuechaseViewController *addVC = [[AddPuechaseViewController alloc]init];
    [self.navigationController pushViewController:addVC animated:YES];
}
- (void)xyMoreBtnAction:(UIButton *)btn
{
    
    NewPurchaseViewController *xyPuechasevc = [[NewPurchaseViewController alloc]init];
    [self.navigationController pushViewController:xyPuechasevc animated:NO];
    self.tabBarController.tabBar.hidden = YES;

}
- (void)myxyMoreBtnAction:(UIButton *)btn
{
    MyPurchaseViewController *myxyPuechasevc = [[MyPurchaseViewController alloc]init];
    [self.navigationController pushViewController:myxyPuechasevc animated:YES];
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)joinxyMoreBtnAction:(UIButton *)btn
{
    JoinPurchaseViewController *joinxyPurchaseVC = [[JoinPurchaseViewController alloc]init];
    [self.navigationController pushViewController:joinxyPurchaseVC animated:YES];
    self.tabBarController.tabBar.hidden = YES;
}
//TOP3点击push
- (void)handleSingleTap1:(UIButton*)btn
{
    PurchaseDetailViewController *purchaseDetailVC =[[PurchaseDetailViewController alloc]init];
   
   
    purchaseDetailVC.purchaseModel =self.topThreeArr[0];
    if (purchaseDetailVC.purchaseModel != nil) {
        [self.navigationController pushViewController:purchaseDetailVC animated:YES];
        self.tabBarController.tabBar.hidden = YES;
    }

}
- (void)handleSingleTap2:(UIButton*)btn
{
    PurchaseDetailViewController *purchaseDetailVC =[[PurchaseDetailViewController alloc]init];
  
    purchaseDetailVC.purchaseModel =self.topThreeArr[1];
    if (purchaseDetailVC.purchaseModel != nil) {
        [self.navigationController pushViewController:purchaseDetailVC animated:YES];
        self.tabBarController.tabBar.hidden = YES;
    }
  
}
- (void)handleSingleTap3:(UIButton*)btn
{
    PurchaseDetailViewController *purchaseDetailVC =[[PurchaseDetailViewController alloc]init];
    
    
    purchaseDetailVC.purchaseModel =self.topThreeArr[2];
    if (purchaseDetailVC.purchaseModel != nil) {
        [self.navigationController pushViewController:purchaseDetailVC animated:YES];
        self.tabBarController.tabBar.hidden = YES;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
